/*
 * Class.h
 *
 *  Created on: Nov 11, 2010
 *      Author: dhovemey
 */

#ifndef CLASS_H_
#define CLASS_H_

#include <cstddef>
#include "runtime/Object.h"
class SourceFile;
class ASTNode;

typedef Object (*Method)(Object *receiver, Object *param1, Object *param2, Object **restOfParams);

class Class {
private:
	const ClassId m_clsId;
	const unsigned m_flags;
	const unsigned m_numFields;
	const unsigned m_numSlots;
	const unsigned m_objectSize;
	ASTNode *m_ast;
	SourceFile *m_srcFile;

	Class(const Class &);
	Class& operator=(const Class &);

public:
	// class ids of the core runtime classes
	enum {
		CLASSID_BOOLEAN,
		CLASSID_CHARACTER,
		CLASSID_INTEGER,
		CLASSID_NIL,
		CLASSID_STRING,
		CLASSID_SYMBOL,

		NUM_CORE_CLASSIDS, // keep this as last member
	};

	enum {
		FLAG_MODULE = (1 << 0),
		FLAG_MAGIC  = (1 << 1),
	};

	Class(ClassId clsId, unsigned flags, unsigned numFields);
	~Class();

	ClassId getClassId() const { return m_clsId; }

	unsigned getFlags() const { return m_flags; }

	unsigned getNumFields() const { return m_numFields; }

	unsigned getNumSlots() const { return m_numSlots; }

	size_t getObjectSize() const { return m_objectSize; }

	void setAST(ASTNode *ast);
	ASTNode *getAST();
	void setSourceFile(SourceFile *srcFile);
	SourceFile *getSourceFile();

	void initialize(Object *obj) const;
};

#endif /* CLASS_H_ */
